package com.fei.wechat.common.model.vo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 描述: 分页对象
 * 版权: Copyright (c) 2018 
 * 公司: 飞翔科技有限公司
 * 作者: 张进飞 
 * 版本: 1.0 
 * 创建日期: 2018年4月17日 
 * 创建时间: 上午9:03:15
 */
public class PagerVo<T> implements Serializable
{
    
    /**
     * 
     */
    private static final long serialVersionUID = 3354403313141491598L;
    
    private Integer currentPage; //页数
    
    private Integer pageSize = 20; //每页条数
    
    private Integer total; //总条数
    
    private Double currentCount; //总页数
    
    private Integer start;
    
    private Integer end;
    
    // 分页数据
    private List<T> data;
    
    public PagerVo()
    {
    }
    
    public PagerVo(Integer currentPage, Integer pageSize, int total)
    {
        this.total = total;
        this.currentPage = currentPage <= 0 ? 1 : currentPage;
        this.pageSize = pageSize;
        BigDecimal b1 = new BigDecimal(Double.toString(total));
        BigDecimal b2 = new BigDecimal(Double.toString(pageSize));
        this.currentCount = Math.ceil(b1.divide(b2, 10, BigDecimal.ROUND_HALF_UP).doubleValue()); //总页数
        int start, end;
        end = this.currentPage * pageSize; //最后条数索引
        //如果最后索引，大于总条数最后索引
        if (end > total)
        {
            end = total;
        }
        start = (this.currentPage - 1) * pageSize;
        this.start = start;
        this.end = end;
    }
    
    public List<T> getData()
    {
        return data;
    }
    
    public void setData(List<T> data)
    {
        this.data = data;
    }
    
    public Integer getCurrentPage()
    {
        return currentPage;
    }
    
    public void setCurrentPage(Integer currentPage)
    {
        this.currentPage = currentPage;
    }
    
    public Integer getPageSize()
    {
        return pageSize;
    }
    
    public void setPageSize(Integer pageSize)
    {
        this.pageSize = pageSize;
    }
    
    public Integer getTotal()
    {
        return total;
    }
    
    public void setTotal(Integer total)
    {
        this.total = total;
    }
    
    public Double getCurrentCount()
    {
        return currentCount;
    }
    
    public void setCurrentCount(Double currentCount)
    {
        this.currentCount = currentCount;
    }
    
    public Integer getStart()
    {
        return start;
    }
    
    public void setStart(Integer start)
    {
        this.start = start;
    }
    
    public Integer getEnd()
    {
        return end;
    }
    
    public void setEnd(Integer end)
    {
        this.end = end;
    }
    
}
